//
//  UIViewController+EJModelPresent.m
//  EJiangOSbeta
//
//  Created by 刘爽 on 2019/9/20.
//  Copyright © 2019 Joyssom. All rights reserved.
//

#import "UIViewController+EJModelPresent.h"
#import "EJBasePresentationController.h"

@implementation UIViewController (EJModelPresent)

- (void)ej_modalPresentViewController:(UIViewController *)viewControllerToPresent bgTap:(BOOL)bgTap animated:(BOOL)flag completion:(void (^)(void))completion {
    viewControllerToPresent.modalPresentationStyle = UIModalPresentationCustom;
    EJBasePresentationController * vc = [[EJBasePresentationController alloc] initWithPresentedViewController:viewControllerToPresent presentingViewController:self];
    vc.bgTap = bgTap;
    viewControllerToPresent.transitioningDelegate = vc;
    [self presentViewController:viewControllerToPresent animated:flag completion:completion];
}

- (void)ej_modalPresentViewController:(UIViewController *)viewControllerToPresent bgTap:(BOOL)bgTap animatedTime:(CGFloat)animatedTime completion:(void (^)(void))completion {
    viewControllerToPresent.modalPresentationStyle = UIModalPresentationCustom;
    EJBasePresentationController * vc = [[EJBasePresentationController alloc] initWithPresentedViewController:viewControllerToPresent presentingViewController:self];
    vc.bgTap = bgTap;
    vc.animatedTime = animatedTime;
    viewControllerToPresent.transitioningDelegate = vc;
    [self presentViewController:viewControllerToPresent animated:YES completion:completion];
}

- (void)ej_showConfirmAlert:(NSString *)message {
    [self ej_showConfirmAlertWithTitle:@"提示" message:message handler:nil];
}

- (void)ej_showConfirmAlertWithTitle:(NSString *)title message:(NSString *)message handler:(void (^)(void))handler {
    if (self == nil || [message length] == 0) {
        return;
    }
    if (![self isKindOfClass:[UIViewController class]]) {
        return;
    }
    UIAlertController * alertC = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        if (handler) {
            handler();
        }
    }];
    [alertC addAction:cancelAction];
    [self presentViewController:alertC animated:YES completion:nil];
}

@end
